Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates CortexaDBStore’s periodic checkpointing concurrency to avoid checkpoint/WAL inconsistencies that could lead to “gaps” during crash recovery.
Changes:
- Capture
state_machineandlast_applied_idunder a single writer-lock acquisition for checkpoint creation (avoids TOCTOU mismatch). - Pass a pre-captured
wal_pathinto the checkpoint thread instead of re-locking solely to fetch it. - Update the checkpoint thread function signature/call sites accordingly.
Comments suppressed due to low confidence (1)
crates/cortexadb-core/src/store.rs:577
WriteAheadLog::truncate_prefix()rewrites+renames the WAL file, but it is currently executed without holding the writer lock. While this thread is truncating, other write operations can still append to the old WAL file handle; those appends will not be present in the rewritten WAL and can be lost whenreopen_wal()swaps the handle. To avoid WAL corruption/data loss, perform WAL flush + truncation +reopen_wal()while holding the samewriterlock (and flush buffers before truncation so buffered entries are included in the rewrite).
// `wal_path` was captured at thread-spawn time — no lock needed.
if let Err(err) =
WriteAheadLog::truncate_prefix(&wal_path, CommandId(last_applied_id))
{
log::error!("cortexadb WAL truncation error: {err}");
} else {
let mut write_guard = match writer.lock() {
Ok(g) => g,
Err(e) => {
log::error!("cortexadb checkpoint error while reopening WAL (lock poisoned): {e}");
continue;
}
};
if let Err(err) = write_guard.engine.reopen_wal() {
log::error!("cortexadb WAL reopen error: {err}");
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+544
to
+559
| let (checkpoint_state, last_applied_id) = match writer.lock() { | ||
| Ok(guard) => { | ||
| let id = guard.engine.last_applied_id().0; | ||
| let state = guard.engine.get_state_machine().clone(); | ||
| (state, id) | ||
| } | ||
| Err(e) => { | ||
| log::error!("cortexadb checkpoint error (lock poisoned): {e}"); | ||
| continue; | ||
| } | ||
| }; | ||
| // Lock released — all I/O happens outside it. | ||
|
|
||
| if let Err(err) = save_checkpoint( | ||
| &checkpoint_path, | ||
| read_snapshot.state_machine(), | ||
| last_applied_id, | ||
| ) { | ||
| if let Err(err) = | ||
| save_checkpoint(&checkpoint_path, &checkpoint_state, last_applied_id) | ||
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Updated the Concurrency model so now there won't be any missing stuff between the checkpoint and the WAL